Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | export const dynamic = 'force-dynamic' import {prisma} from '@/lib/db' import {requireSession} from '@/lib/guard' import {logActivity} from '@/lib/songs' import {formatDay, keyOf} from '@/lib/availability' import {route} from '@/lib/route' export const DELETE = route( async (_req: Request, {params}: {params: {id: string}}) => { const {user, band, isAdmin} = await requireSession() const r = await prisma.rehearsal.findFirst({ where: {id: params.id, bandId: band.id}, }) if (!r) return new Response('Not Found', {status: 404}) if (r.createdById !== user.id && !isAdmin) return new Response('Forbidden', {status: 403}) await prisma.$transaction(async (tx) => { await tx.rehearsal.delete({where: {id: r.id}}) await logActivity(tx, { bandId: band.id, userId: user.id, action: 'rehearsal.delete', targetType: 'rehearsal', targetId: r.id, summary: `cancelled the rehearsal on ${formatDay(keyOf(r.date))}`, }) }) return new Response(null, {status: 204}) }, ) |